<template>
	<view class="page">
		<view class="list" v-for="item in list" :key="item.Id" @click.stop="tap(item)">
			<view class="list__left">
				<u-icon name="order" size="15"></u-icon>
			</view>
			<view class="list__center">
				<view class="list__center--title">{{item.FormTitle}}</view>
				<view class="list__center--time">
					<text>最近编辑：</text>
					<text>{{item.UpdateTime}}</text>
				</view>
			</view>
			<view class="list__right" @click.stop="del(item.Id)">
				<image src="@/static/theme/default/home/comment/shanchu.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import _custom from '@/common/_custom.js';
	import _data from '@/common/_data.js'
	
	export default {
		data() {
			return {
				pxid: _data.localData('userid'),
				list: []
			}
		},
		onShow() {
			this.getSmartFormDraftList();
		},
		methods: {
			/**
			 * 获取动态表单草稿列表
			 * @param {Object} v
			 */
			getSmartFormDraftList() {
				let that = this;
				_custom.getDataJava({
					apiname: 'getSmartFormDraftList',
					apiparam: {
						keyword: "", //关键词模糊查询
						typename: "",
						sorting: "asc", //asc:最早，desc:最新
						createpxid: this.pxid
					},
					success(res) {
						that.list = res;
					},
				})
			},
			/**
			 * 删除表单模板
			 * @param {Object} v
			 */
			flagDeleteSmartForm(v) {
				let that = this;
				_custom.getDataJava({
					apiname: 'flagDeleteSmartForm',
					code: 2,
					apiparam: {
						formid: v
					},
					success(res) {
						uni.showToast({
							title: "删除成功",
							icon: 'none'
						})
						that.getSmartFormDraftList();
					},
					fail() {
						uni.showToast({
							title: "删除失败",
							icon: 'none'
						})
					}
				})
			},
			del(v) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确认要删除吗？',
					success(res) {
						if(res.confirm) {
							that.flagDeleteSmartForm(v)
						}
					}
				})
			},
			tap(v) {
				let obj = JSON.parse(JSON.stringify(v));
				let json = v.FormJson.replace(/%22/g,'"');
				try {
					obj.FormJson = JSON.parse(json);
				} catch(e) {
					console.log(e)
				}
				console.log(v)
				uni.navigateTo({
					url: '../smart-form-add/index?data=' + JSON.stringify(obj)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.list {
		height: 120rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #eee;
		
		&__left,&__right {
			width: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			
			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
		
		&__center {
			flex: 1;
			height: 100%;
			
			&--title {
				font-size: 30rpx;
				height: 50%;
				flex: 1;
				line-height: 70rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
			
			&--time {
				font-size: 25rpx;
				height: 50%;
			}
		}
	}
</style>
